home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d5 / tictacto.arc / TICTACTO.BAS (.txt) < prev   
Encoding:
GW-BASIC  |  1985-11-17  |  18.0 KB  |  587 lines

  1. 100  CLS
  2. 110  A$=STRING$(80,205)
  3. 120  PRINT A$
  4. 130  PRINT TAB(29)"TIC TAC TOE 2010-A.BAS "
  5. 140  COLOR 23,0,0
  6. 150  PRINT :PRINT :PRINT TAB(38)"IPCO"
  7. 160  COLOR 7,0,0
  8. 170  PRINT :PRINT :PRINT TAB(29)"INTERNATIONAL PC OWNERS"
  9. 180  PRINT :PRINT :PRINT TAB(17)"p.o. box 10426, pittsburgh, pennsylvania 15234"
  10. 190  PRINT A$
  11. 200  PRINT :PRINT :PRINT :PRINT :PRINT
  12. 210  PRINT TAB(28)"PRESS ANY KEY TO CONTINUE"
  13. 220  A$=INKEY$:IF A$="" THEN 220
  14. 230  CLS
  15. 240  REM  **************************************************
  16. 250  REM  * Name - Tic Tac Toe                             *
  17. 260  REM  * Author - David R Quiggin                       *
  18. 270  REM  * Remarks - If you like this game, I am selling  *
  19. 280  REM  *  a package of 10 games and programs on disk    *
  20. 290  REM  *  for $19.95 plus 2.00 shipping and handling.   *
  21. 300  REM  *  To order or request more information send to: *
  22. 310  REM  *     Pittsburgh Computer Exchange               *
  23. 320  REM  *     112 Marble Drive                           *
  24. 330  REM *     Bridgeville, Pa, 15017                     *
  25. 340  REM **************************************************
  26. 350  SCREEN 0,0,0:KEY OFF: CLS: WIDTH 80
  27. 360    DIM SQ(9)  'store whether positon used
  28. 370    GOSUB 5950 'seed random nbr
  29. 380  CLS
  30. 390  GOSUB 3670  'initialize
  31. 400    LOCATE 5,47,0:PRINT "Choose which game you want"
  32. 410    LOCATE 7,47,0:PRINT "  1 - 2 persons play"
  33. 420    LOCATE 9,47,0:PRINT "  2 - Basic game against the"
  34. 430    LOCATE 10,47,0:PRINT "      computer"
  35. 440    LOCATE 12,47,0:PRINT "  3 - More difficult game"
  36. 450    LOCATE 13,47,0:PRINT "      against the computer"
  37. 460    LOCATE 15,47,0:PRINT "  4 - Most difficult game"
  38. 470    LOCATE 16,47,0:PRINT "      against the computer"
  39. 480    LOCATE 18,47,0:PRINT "  5 - Instructions"
  40. 490    LOCATE 20,50,0:PRINT "Which do you want?"
  41. 500    LOCATE 21,50,0:PRINT " Enter the number __"
  42. 510     CH$=INKEY$:IF CH$="" THEN GOTO 510  'loop to sense input
  43. 520      IF CH$=CHR$(27) THEN GOTO 710    'ESC to end
  44. 530     IF CH$="1" OR CH$="2" OR CH$="3" OR CH$="4" OR CH$="5" THEN GOTO 560
  45. 540       LOCATE 22,50,0:PRINT "Error, please reenter"
  46. 550       GOTO 490
  47. 560     IF CH$="1" THEN GOSUB 1390 ' 2 player game
  48. 570     IF CH$="2" THEN GOSUB 710 ' Basic game against computer
  49. 580     IF CH$="3" THEN GOSUB 710 ' more difficult game against computer
  50. 590     IF CH$="4" THEN GOSUB 5110 ' Most difficult game against computer
  51. 600     IF CH$="5" THEN GOSUB 4070:GOTO 400  ' give instructions
  52. 610   LOCATE 20,47,0:PRINT " Play again (Y or N)"
  53. 620    YN$=INKEY$
  54. 630    IF YN$="" THEN GOTO 620
  55. 640    IF YN$="Y" OR YN$="y" THEN GOTO 380
  56. 650    IF YN$="1" OR YN$="2" OR YN$="3" OR YN$="4" THEN GOTO 660 ELSE GOTO 690
  57. 660      CH$=YN$
  58. 670      CLS:GOSUB 3670  'initialize
  59. 680      GOTO 560  'start the appropriate game (without having to go thru menu)
  60. 690  SYSTEM
  61. 700  END '******
  62. 710  REM -- Games 2 and 3 against the Computer Subroutine ---
  63. 720   FOR I=1 TO 9 'initialize array for storing moves
  64. 730     SQ(I)=0
  65. 740   NEXT I
  66. 750   GOSUB 4230  'erase box
  67. 760  REM  X First move
  68. 770   GOSUB 1920 'ask for and make X move
  69. 780  REM  O Second move Computer move
  70. 790   I=INT((RND*8)+1) 'pick random computer move
  71. 800   IF SQ(I) <> 0 THEN GOTO 790  'if square filled pick another
  72. 810   MOVE=I
  73. 820   GOSUB 3360  'load coordinates for move
  74. 830   GOSUB 3560  'draw move
  75. 840  REM  X Third move
  76. 850   GOSUB 1920    'ask for and make X move
  77. 860  REM  O Fourth move, Computer move
  78. 870   IF CH$="2" THEN GOTO 900  'easier game
  79. 880    MOVE=0:GOSUB 4280   'check for 2 in row, win and stop opponent
  80. 890    IF MOVE=0 THEN GOTO 900 ELSE GOTO 930  'if not 2 in row do random
  81. 900   I=INT((RND*8)+1)  'pick random computer move
  82. 910   IF SQ(I) <> 0 THEN GOTO 900  'if square filled pick another
  83. 920   MOVE=I
  84. 930   GOSUB 3360:GOSUB 3560  'make move
  85. 940  REM  X Fifth move
  86. 950   GOSUB 1920    'ask for and make X move
  87. 960   WINSW=0:GOSUB 2270  'check for win
  88. 970   IF WINSW=4 THEN GOTO 1340   'X wins
  89. 980  REM  O Sixth move, Computer move
  90. 990   IF CH$="2" THEN GOTO 1020  'easier game
  91. 1000    MOVE=0:GOSUB 4280   'check for 2 in row, win and stop opponent
  92. 1010    IF MOVE=0 THEN GOTO 1020 ELSE GOTO 1050  'if not 2 in row do random
  93. 1020   I=INT((RND*8)+1)  'pick random computer move
  94. 1030   IF SQ(I) <> 0 THEN GOTO 1020  'if square filled pick another
  95. 1040   MOVE=I
  96. 1050   GOSUB 3360:GOSUB 3560  'make move
  97. 1060   WINSW=0:GOSUB 2270  'check for win
  98. 1070   IF WINSW=1 THEN GOTO 1300   'Computer wins
  99. 1080  REM  X Seventh move
  100. 1090   GOSUB 1920    'ask for and make X move
  101. 1100   WINSW=0:GOSUB 2270  'check for win
  102. 1110   IF WINSW=4 THEN GOTO 1340   'X wins
  103. 1120  REM  O Eighth move, Computer move
  104. 1130   IF CH$="2" THEN GOTO 1160  'easier game
  105. 1140    MOVE=0:GOSUB 4280   'check for 2 in row, win and stop opponent
  106. 1150    IF MOVE=0 THEN GOTO 1160 ELSE GOTO 1190  'if not 2 in row do random
  107. 1160   I=INT((RND*8)+1)  'pick random computer move
  108. 1170   IF SQ(I) <> 0 THEN GOTO 1160  'if square filled pick another
  109. 1180   MOVE=I
  110. 1190   GOSUB 3360:GOSUB 3560  'make move
  111. 1200   WINSW=0:GOSUB 2270  'check for win
  112. 1210   IF WINSW=1 THEN GOTO 1300   'Computer wins
  113. 1220  REM  X Nineth move
  114. 1230   GOSUB 1920    'ask for and make X move
  115. 1240   WINSW=0:GOSUB 2270  'check for win
  116. 1250   IF WINSW=4 THEN GOTO 1340   'X wins
  117. 1260  REM -- TIE --
  118. 1270   BEEP
  119. 1280   LOCATE 12,55,0:PRINT "  TIE    "
  120. 1290   GOTO 1370
  121. 1300  REM -- O WINS --
  122. 1310   BEEP
  123. 1320   LOCATE 12,55,0:PRINT " O - WINS"
  124. 1330   GOTO 1370
  125. 1340  REM -- X WINS --
  126. 1350   BEEP
  127. 1360   LOCATE 12,55,0:PRINT " X - WINS"
  128. 1370  COLOR 7,0  'Turn of blinking
  129. 1380  RETURN '----
  130. 1390  REM -- 2 player game Subroutine --
  131. 1400   FOR I=1 TO 9 'initialize array
  132. 1410     SQ(I)=0
  133. 1420   NEXT I
  134. 1430    MOVECNTR=0
  135. 1440    XOSW=4   'set to x move first
  136. 1450   GOSUB 4230  'erase box
  137. 1460  REM  X First move
  138. 1470   GOSUB 1920 'ask for and make X move
  139. 1480   WINSW=0:GOSUB 2270  'check for win
  140. 1490   IF WINSW=4 THEN GOTO 1880  'X wins
  141. 1500  REM  O Second move
  142. 1510   GOSUB 2090 'ask for and make O move
  143. 1520   WINSW=0:GOSUB 2270  'check for win
  144. 1530   IF WINSW=1 THEN GOTO 1850 'O wins
  145. 1540  REM  X Third move
  146. 1550   GOSUB 1920 'ask for and make X move
  147. 1560   WINSW=0:GOSUB 2270  'check for win
  148. 1570   IF WINSW=4 THEN GOTO 1880 'X wins
  149. 1580  REM  O Fourth move
  150. 1590   GOSUB 2090 'ask for and make O move
  151. 1600   WINSW=0:GOSUB 2270  'check for win
  152. 1610   IF WINSW=1 THEN GOTO 1850 'O wins
  153. 1620  REM  X Fifth move
  154. 1630   GOSUB 1920 'ask for and make X move
  155. 1640   WINSW=0:GOSUB 2270  'check for win
  156. 1650   IF WINSW=4 THEN GOTO 1880 'X wins
  157. 1660  REM  O Sixth move
  158. 1670   GOSUB 2090 'ask for and make O move
  159. 1680   WINSW=0:GOSUB 2270 'check for win
  160. 1690   IF WINSW=1 THEN GOTO 1850 'O wins
  161. 1700  REM  X Seventh move
  162. 1710   GOSUB 1920 'ask for and make X move
  163. 1720   WINSW=0:GOSUB 2270 'check for win
  164. 1730   IF WINSW=4 THEN GOTO 1880 'X wins
  165. 1740  REM  O Eighth move
  166. 1750   GOSUB 2090 'ask for and make O move
  167. 1760   WINSW=0:GOSUB 2270  'check for win
  168. 1770   IF WINSW=1 THEN GOTO 1850 'O wins
  169. 1780  REM  X Nineth move
  170. 1790   GOSUB 1920 'ask for and make X move
  171. 1800   WINSW=0:GOSUB 2270  'check for win
  172. 1810   IF WINSW=4 THEN GOTO 1880 'X wins
  173. 1820  REM
  174. 1830     BEEP:LOCATE 12,55,0:PRINT "  TIE    ":BEEP
  175. 1840   GOTO 1900
  176. 1850     LOCATE 12,55,0:PRINT " O - WINS"
  177. 1860     BEEP
  178. 1870   GOTO 1900
  179. 1880     LOCATE 12,55,0:PRINT " X - WINS"
  180. 1890     BEEP
  181. 1900    COLOR 7,0  'return to default color, ie. end flashing
  182. 1910  RETURN  '----
  183. 1920  REM --- Do X move subroutine ---
  184. 1930    LOCATE 7,46,0:PRINT ERASE1$
  185. 1940    LOCATE 8,46,0:PRINT ERASE1$
  186. 1950    LOCATE 9,46,0:PRINT ERASE1$
  187. 1960   LOCATE 7,47,0:PRINT "Enter move for X player"
  188. 1970   IN1$=INKEY$
  189. 1980   IF IN1$="" GOTO 1970
  190. 1990   IF ASC(IN1$) < 49 THEN GOTO 1970  'insure number 1-9
  191. 2000   IF ASC(IN1$) > 57 THEN GOTO 1970
  192. 2010    MOVE=VAL(IN1$) 'convert to number
  193. 2020    IN1$=""  'clear out
  194. 2030    SW=0   'set valid move switch
  195. 2040    GOSUB 3360  'load coordinates for move
  196. 2050    IF SW=1 THEN GOSUB 3470:GOTO 2080
  197. 2060      LOCATE 8,47,0:PRINT "That square filled, reenter"
  198. 2070      GOTO 1960
  199. 2080  RETURN  '----
  200. 2090  REM --- Do O move Subroutine ---
  201. 2100    LOCATE 7,46,0:PRINT ERASE1$
  202. 2110    LOCATE 8,46,0:PRINT ERASE1$
  203. 2120    LOCATE 9,46,0:PRINT ERASE1$
  204. 2130   LOCATE 7,47,0:PRINT "Enter move for O player"
  205. 2140   IN1$=INKEY$
  206. 2150   IF IN1$="" GOTO 2140
  207. 2160   IF ASC(IN1$) < 49 THEN GOTO 2140  'insure number 1-9
  208. 2170   IF ASC(IN1$) > 57 THEN GOTO 2140
  209. 2180    MOVE=VAL(IN1$) 'convert to number
  210. 2190    IN1$=""  'clear out
  211. 2200    SW=0   'set valid move switch
  212. 2210    GOSUB 3360  'load coordinates for move
  213. 2220    IF SW=1 THEN GOSUB 3560:GOTO 2260
  214. 2230      LOCATE 8,47,0:PRINT "That square filled, reenter"
  215. 2240      LOCATE 7,46,0:PRINT ERASE1$    'erase any err messages
  216. 2250      GOTO 2130
  217. 2260  RETURN  '----
  218. 2270  REM --- Scan for a win ---
  219. 2280   IF SQ(1)=1 AND SQ(5)=1 AND SQ(9)=1 THEN GOTO 2290 ELSE GOTO 2350 'O wins
  220. 2290    WINSW=1
  221. 2300    COLOR 23
  222. 2310    R=2:C=14:GOSUB 3560  'draw flashing O in sq 1
  223. 2320    R=10:C=22:GOSUB 3560  'O in sq 5
  224. 2330    R=18:C=30:GOSUB 3560  'O in sq 9
  225. 2340    GOTO 3350
  226. 2350   IF SQ(7)=1 AND SQ(5)=1 AND SQ(3)=1 THEN GOTO 2360 ELSE GOTO 2420
  227. 2360    WINSW=1
  228. 2370    COLOR 23
  229. 2380    R=18:C=14:GOSUB 3560  'draw flashing O in sq 7
  230. 2390    R=10:C=22:GOSUB 3560  'sq 5
  231. 2400    R=2:C=30:GOSUB 3560  'sq 3
  232. 2410    GOTO 3350
  233. 2420   IF SQ(1)=1 AND SQ(2)=1 AND SQ(3)=1 THEN GOTO 2430 ELSE GOTO 2490
  234. 2430    WINSW=1
  235. 2440    COLOR 23
  236. 2450    R=2:C=14:GOSUB 3560  'draw flashing O in sq 1
  237. 2460    R=2:C=22:GOSUB 3560  'sq 2
  238. 2470    R=2:C=30:GOSUB 3560  'sq 3
  239. 2480    GOTO 3350
  240. 2490   IF SQ(4)=1 AND SQ(5)=1 AND SQ(6)=1 THEN GOTO 2500 ELSE GOTO 2560
  241. 2500    WINSW=1
  242. 2510    COLOR 23
  243. 2520    R=10:C=14:GOSUB 3560  'draw flashing O in sq 4
  244. 2530    R=10:C=22:GOSUB 3560  'sq 5
  245. 2540    R=10:C=30:GOSUB 3560  'sq 6
  246. 2550    GOTO 3350
  247. 2560   IF SQ(7)=1 AND SQ(8)=1 AND SQ(9)=1 THEN GOTO 2570 ELSE GOTO 2630
  248. 2570    WINSW=1
  249. 2580    COLOR 23
  250. 2590    R=18:C=14:GOSUB 3560  'draw flashing O in sq 7
  251. 2600    R=18:C=22:GOSUB 3560  'sq 8
  252. 2610    R=18:C=30:GOSUB 3560  'sq 9
  253. 2620    GOTO 3350
  254. 2630   IF SQ(1)=1 AND SQ(4)=1 AND SQ(7)=1 THEN GOTO 2640 ELSE GOTO 2700
  255. 2640    WINSW=1
  256. 2650    COLOR 23
  257. 2660    R=2:C=14:GOSUB 3560  'flashing O in sq 1
  258. 2670    R=10:C=14:GOSUB 3560  'sq 4
  259. 2680    R=18:C=14:GOSUB 3560  'sq 7
  260. 2690    GOTO 3350
  261. 2700   IF SQ(2)=1 AND SQ(5)=1 AND SQ(8)=1 THEN GOTO 2710 ELSE GOTO 2770
  262. 2710    WINSW=1
  263. 2720    COLOR 23
  264. 2730    R=2:C=22:GOSUB 3560  'flashing O in sq 2
  265. 2740    R=10:C=22:GOSUB 3560  'sq 5
  266. 2750    R=18:C=22:GOSUB 3560  'sq 8
  267. 2760    GOTO 3350
  268. 2770   IF SQ(3)=1 AND SQ(6)=1 AND SQ(9)=1 THEN GOTO 2780 ELSE GOTO 2840
  269. 2780    WINSW=1
  270. 2790    COLOR 23
  271. 2800    R=2:C=30:GOSUB 3560  'flashing O in sq 3
  272. 2810    R=10:C=30:GOSUB 3560  'sq 6
  273. 2820    R=18:C=30:GOSUB 3560  'sq 9
  274. 2830    GOTO 3350
  275. 2840  REM
  276. 2850   IF SQ(1)=4 AND SQ(5)=4 AND SQ(9)=4 THEN GOTO 2860 ELSE GOTO 2920 'X wins
  277. 2860    WINSW=4
  278. 2870    COLOR 23
  279. 2880    R=2:C=14:GOSUB 3470  'flashing X in sq 1
  280. 2890    R=10:C=22:GOSUB 3470  'sq 5
  281. 2900    R=18:C=30:GOSUB 3470  'sq 9
  282. 2910    GOTO 3350
  283. 2920   IF SQ(7)=4 AND SQ(5)=4 AND SQ(3)=4 THEN GOTO 2930 ELSE GOTO 2990
  284. 2930    WINSW=4
  285. 2940    COLOR 23
  286. 2950    R=18:C=14:GOSUB 3470  'flashing X in sq 7
  287. 2960    R=10:C=22:GOSUB 3470  'sq 5
  288. 2970    R=2:C=30:GOSUB 3470  'sq 3
  289. 2980    GOTO 3350
  290. 2990   IF SQ(1)=4 AND SQ(2)=4 AND SQ(3)=4 THEN GOTO 3000 ELSE GOTO 3060
  291. 3000    WINSW=4
  292. 3010    COLOR 23
  293. 3020    R=2:C=14:GOSUB 3470  'flashing X in sq 1
  294. 3030    R=2:C=22:GOSUB 3470  'sq 2
  295. 3040    R=2:C=30:GOSUB 3470  'sq 3
  296. 3050    GOTO 3350
  297. 3060   IF SQ(4)=4 AND SQ(5)=4 AND SQ(6)=4 THEN GOTO 3070 ELSE GOTO 3120
  298. 3070    WINSW=4:COLOR 23
  299. 3080    R=10:C=14:GOSUB 3470  'flashing X in sq 4
  300. 3090    R=10:C=22:GOSUB 3470  'sq 5
  301. 3100    R=10:C=30:GOSUB 3470  'sq 6
  302. 3110    GOTO 3350
  303. 3120   IF SQ(7)=4 AND SQ(8)=4 AND SQ(9)=4 THEN GOTO 3130 ELSE GOTO 3180
  304. 3130    WINSW=4:COLOR 23
  305. 3140    R=18:C=14:GOSUB 3470  'flashing X in sq 7
  306. 3150    R=18:C=22:GOSUB 3470  'sq 8
  307. 3160    R=18:C=30:GOSUB 3470  'sq 9
  308. 3170    GOTO 3350
  309. 3180   IF SQ(1)=4 AND SQ(4)=4 AND SQ(7)=4 THEN GOTO 3190 ELSE GOTO 3240
  310. 3190    WINSW=4:COLOR 23
  311. 3200    R=2:C=14:GOSUB 3470  'flashing X in sq 1
  312. 3210    R=10:C=14:GOSUB 3470  'sq 4
  313. 3220    R=18:C=14:GOSUB 3470  'sq 7
  314. 3230    GOTO 3350
  315. 3240   IF SQ(2)=4 AND SQ(5)=4 AND SQ(8)=4 THEN GOTO 3250 ELSE GOTO 3300
  316. 3250    WINSW=4:COLOR 23
  317. 3260    R=2:C=22:GOSUB 3470  'flashing X in sq 2
  318. 3270    R=10:C=22:GOSUB 3470  'sq 5
  319. 3280    R=18:C=22:GOSUB 3470  'sq 8
  320. 3290    GOTO 3350
  321. 3300   IF SQ(3)=4 AND SQ(6)=4 AND SQ(9)=4 THEN GOTO 3310 ELSE GOTO 3350
  322. 3310    WINSW=4:COLOR 23
  323. 3320    R=2:C=30:GOSUB 3470  'draw flashing X in sq 3
  324. 3330    R=10:C=30:GOSUB 3470  'sq 6
  325. 3340    R=18:C=30:GOSUB 3470  'sq 9
  326. 3350  RETURN '----
  327. 3360  REM --- Load coordinates for move ---
  328. 3370    IF MOVE=1 AND SQ(1)=0 THEN R=2:C=14:SW=1:GOTO 3460
  329. 3380    IF MOVE=2 AND SQ(2)=0 THEN R=2:C=22:SW=1:GOTO 3460
  330. 3390    IF MOVE=3 AND SQ(3)=0 THEN R=2:C=30:SW=1:GOTO 3460
  331. 3400    IF MOVE=4 AND SQ(4)=0 THEN R=10:C=14:SW=1:GOTO 3460
  332. 3410    IF MOVE=5 AND SQ(5)=0 THEN R=10:C=22:SW=1:GOTO 3460
  333. 3420    IF MOVE=6 AND SQ(6)=0 THEN R=10:C=30:SW=1:GOTO 3460
  334. 3430    IF MOVE=7 AND SQ(7)=0 THEN R=18:C=14:SW=1:GOTO 3460
  335. 3440    IF MOVE=8 AND SQ(8)=0 THEN R=18:C=22:SW=1:GOTO 3460
  336. 3450    IF MOVE=9 AND SQ(9)=0 THEN R=18:C=30:SW=1:GOTO 3460
  337. 3460  RETURN '----
  338. 3470  REM --- Draw X Subroutine ---
  339. 3480   FOR I=0 TO 4
  340. 3490     LOCATE R+I,C+I,0:PRINT CHR$(D)
  341. 3500     LOCATE R+I,C+4-I,0:PRINT CHR$(D)
  342. 3510   NEXT I
  343. 3520   SQ(MOVE)=4     '4 represents X, 1 represents O and 0 means empty
  344. 3530    XOSW=1   'set next move to be Os
  345. 3540    MOVECNTR=MOVECNTR+1
  346. 3550  RETURN '----
  347. 3560  REM --- Draw O Subroutine ---
  348. 3570   FOR I=0 TO 4
  349. 3580     LOCATE R,C+I,0:PRINT CHR$(D)
  350. 3590     LOCATE R+I,C+4,0:PRINT CHR$(D)
  351. 3600     LOCATE R+4,C+4-I,0:PRINT CHR$(D)
  352. 3610     LOCATE R+4-I,C,0:PRINT CHR$(D)
  353. 3620   NEXT I
  354. 3630   SQ(MOVE)=1     '4 represents X, 1 represents O and 0 means empty
  355. 3640    XOSW=1   'set next move to be Os
  356. 3650    MOVECNTR=MOVECNTR+1
  357. 3660  RETURN '----
  358. 3670  REM -- Subroutine to draw lines and initialize ---
  359. 3680    D=219   'density of Xs and Os
  360. 3690    R=10
  361. 3700    C=22
  362. 3710    FILLED=0
  363. 3720    ERASE1$="                             "  'used to erase box
  364. 3730   FOR I=0 TO 9
  365. 3740     SQ(I)=0
  366. 3750   NEXT I
  367. 3760   FOR I=13 TO 35
  368. 3770    LOCATE 8,I,0:PRINT CHR$(219)
  369. 3780    LOCATE 16,I,0:PRINT CHR$(219)
  370. 3790   NEXT I
  371. 3800   FOR I=1 TO 23
  372. 3810    LOCATE I,20,0:PRINT CHR$(219)
  373. 3820    LOCATE I,28,0:PRINT CHR$(219)
  374. 3830   NEXT I
  375. 3840   LOCATE 7,16,0:PRINT "1"
  376. 3850   LOCATE 7,24,0:PRINT "2"
  377. 3860   LOCATE 7,32,0:PRINT "3"
  378. 3870   LOCATE 15,16,0:PRINT "4"
  379. 3880   LOCATE 15,24,0:PRINT "5"
  380. 3890   LOCATE 15,32,0:PRINT "6"
  381. 3900   LOCATE 23,16,0:PRINT "7"
  382. 3910   LOCATE 23,24,0:PRINT "8"
  383. 3920   LOCATE 23,32,0:PRINT "9"
  384. 3930   FOR I=2 TO 22
  385. 3940    LOCATE I,45,0:PRINT CHR$(186)
  386. 3950    LOCATE I,75,0:PRINT CHR$(186)
  387. 3960   NEXT I
  388. 3970    LOCATE 1,45,0:PRINT CHR$(201)
  389. 3980    LOCATE 1,75,0:PRINT CHR$(187)
  390. 3990    LOCATE 23,45,0:PRINT CHR$(200)
  391. 4000    LOCATE 23,75,0:PRINT CHR$(188)
  392. 4010   FOR I=46 TO 74
  393. 4020    LOCATE 1,I,0:PRINT CHR$(205)
  394. 4030    LOCATE 23,I,0:PRINT CHR$(205)
  395. 4040   NEXT I
  396. 4050    LOCATE 3,55,0:PRINT "TIC TAC TOE"
  397. 4060  RETURN '----
  398. 4070  REM --- Print instructions subroutine ---
  399. 4080    GOSUB 4230  'erase box
  400. 4090    LOCATE 5,47,0:PRINT "WIN - by placing three X or"
  401. 4100    LOCATE 6,47,0:PRINT "      O in a straight line"
  402. 4110    LOCATE 7,47,0:PRINT "      (vertical, horizontal"
  403. 4120    LOCATE 8,47,0:PRINT "      or diagonal)"
  404. 4130    LOCATE 10,47,0:PRINT "Move by entering the number"
  405. 4140    LOCATE 11,47,0:PRINT " of the square you want to"
  406. 4150    LOCATE 12,47,0:PRINT " move to."
  407. 4160    LOCATE 14,47,0:PRINT "You cannot move to a square"
  408. 4170    LOCATE 15,47,0:PRINT " that is filled."
  409. 4180     LOCATE 18,47,0:PRINT "Press any key to continue."
  410. 4190      DEL$=INKEY$:IF DEL$="" THEN GOTO 4190  'sense input - delay only
  411. 4200    GOSUB 4230  'erase box
  412. 4210  RETURN '----
  413. 4220  REM
  414. 4230  REM --- Erase box Subroutine ---
  415. 4240    FOR I=4 TO 22
  416. 4250      LOCATE I,46,0:PRINT ERASE1$
  417. 4260    NEXT I
  418. 4270  RETURN '----
  419. 4280  REM --- Check for Win move for O ---
  420. 4290   IF SQ(1)+SQ(2)+SQ(3)=2 GOTO 4300 ELSE GOTO 4340
  421. 4300    IF SQ(1)=0 THEN MOVE=1
  422. 4310    IF SQ(2)=0 THEN MOVE=2
  423. 4320    IF SQ(3)=0 THEN MOVE=3
  424. 4330    GOTO 5100  ' out of subroutine
  425. 4340   IF SQ(4)+SQ(5)+SQ(6)=2 GOTO 4350 ELSE GOTO 4390
  426. 4350    IF SQ(4)=0 THEN MOVE=4
  427. 4360    IF SQ(5)=0 THEN MOVE=5
  428. 4370    IF SQ(6)=0 THEN MOVE=6
  429. 4380    GOTO 5100  ' out
  430. 4390   IF SQ(7)+SQ(8)+SQ(9)=2 GOTO 4400 ELSE GOTO 4440
  431. 4400    IF SQ(7)=0 THEN MOVE=7
  432. 4410    IF SQ(8)=0 THEN MOVE=8
  433. 4420    IF SQ(9)=0 THEN MOVE=9
  434. 4430    GOTO 5100  ' out
  435. 4440   IF SQ(1)+SQ(4)+SQ(7)=2 GOTO 4450 ELSE GOTO 4490
  436. 4450    IF SQ(1)=0 THEN MOVE=1
  437. 4460    IF SQ(4)=0 THEN MOVE=4
  438. 4470    IF SQ(7)=0 THEN MOVE=7
  439. 4480    GOTO 5100  ' out
  440. 4490   IF SQ(2)+SQ(5)+SQ(8)=2 GOTO 4500 ELSE GOTO 4540
  441. 4500    IF SQ(2)=0 THEN MOVE=2
  442. 4510    IF SQ(5)=0 THEN MOVE=5
  443. 4520    IF SQ(8)=0 THEN MOVE=8
  444. 4530    GOTO 5100  ' out
  445. 4540   IF SQ(3)+SQ(6)+SQ(9)=2 GOTO 4550 ELSE GOTO 4590
  446. 4550    IF SQ(3)=0 THEN MOVE=3
  447. 4560    IF SQ(6)=0 THEN MOVE=6
  448. 4570    IF SQ(9)=0 THEN MOVE=9
  449. 4580    GOTO 5100  ' out
  450. 4590   IF SQ(1)+SQ(5)+SQ(9)=2 GOTO 4600 ELSE GOTO 4640
  451. 4600    IF SQ(1)=0 THEN MOVE=1
  452. 4610    IF SQ(5)=0 THEN MOVE=5
  453. 4620    IF SQ(9)=0 THEN MOVE=9
  454. 4630    GOTO 5100  ' out
  455. 4640   IF SQ(3)+SQ(5)+SQ(7)=2 GOTO 4650 ELSE GOTO 4710
  456. 4650    IF SQ(3)=0 THEN MOVE=3
  457. 4660    IF SQ(5)=0 THEN MOVE=5
  458. 4670    IF SQ(7)=0 THEN MOVE=7
  459. 4680    GOTO 5100  ' out of subroutine
  460. 4690  REM
  461. 4700  REM -- Following checks to stop 2 Xs in a row --
  462. 4710   IF SQ(1)+SQ(2)+SQ(3)=8 GOTO 4720 ELSE GOTO 4760
  463. 4720    IF SQ(1)=0 THEN MOVE=1
  464. 4730    IF SQ(2)=0 THEN MOVE=2
  465. 4740    IF SQ(3)=0 THEN MOVE=3
  466. 4750    GOTO 5100  ' out of subroutine
  467. 4760   IF SQ(4)+SQ(5)+SQ(6)=8 GOTO 4770 ELSE GOTO 4810
  468. 4770    IF SQ(4)=0 THEN MOVE=4
  469. 4780    IF SQ(5)=0 THEN MOVE=5
  470. 4790    IF SQ(6)=0 THEN MOVE=6
  471. 4800    GOTO 5100  ' out
  472. 4810   IF SQ(7)+SQ(8)+SQ(9)=8 GOTO 4820 ELSE GOTO 4860
  473. 4820    IF SQ(7)=0 THEN MOVE=7
  474. 4830    IF SQ(8)=0 THEN MOVE=8
  475. 4840    IF SQ(9)=0 THEN MOVE=9
  476. 4850    GOTO 5100  ' out
  477. 4860   IF SQ(1)+SQ(4)+SQ(7)=8 GOTO 4870 ELSE GOTO 4910
  478. 4870    IF SQ(1)=0 THEN MOVE=1
  479. 4880    IF SQ(4)=0 THEN MOVE=4
  480. 4890    IF SQ(7)=0 THEN MOVE=7
  481. 4900    GOTO 5100  ' out
  482. 4910   IF SQ(2)+SQ(5)+SQ(8)=8 GOTO 4920 ELSE GOTO 4960
  483. 4920    IF SQ(2)=0 THEN MOVE=2
  484. 4930    IF SQ(5)=0 THEN MOVE=5
  485. 4940    IF SQ(8)=0 THEN MOVE=8
  486. 4950    GOTO 5100  ' out
  487. 4960   IF SQ(3)+SQ(6)+SQ(9)=8 GOTO 4970 ELSE GOTO 5010
  488. 4970    IF SQ(3)=0 THEN MOVE=3
  489. 4980    IF SQ(6)=0 THEN MOVE=6
  490. 4990    IF SQ(9)=0 THEN MOVE=9
  491. 5000    GOTO 5100  ' out
  492. 5010   IF SQ(1)+SQ(5)+SQ(9)=8 GOTO 5020 ELSE GOTO 5060
  493. 5020    IF SQ(1)=0 THEN MOVE=1
  494. 5030    IF SQ(5)=0 THEN MOVE=5
  495. 5040    IF SQ(9)=0 THEN MOVE=9
  496. 5050    GOTO 5100  ' out
  497. 5060   IF SQ(3)+SQ(5)+SQ(7)=8 GOTO 5070 ELSE GOTO 5100
  498. 5070    IF SQ(3)=0 THEN MOVE=3
  499. 5080    IF SQ(5)=0 THEN MOVE=5
  500. 5090    IF SQ(7)=0 THEN MOVE=7
  501. 5100  RETURN '----
  502. 5110  REM --- Most difficult game against the Computer 4 ---
  503. 5120   FOR I=1 TO 9   'initialize array that indicates empty squares
  504. 5130     SQ(I)=0
  505. 5140   NEXT I
  506. 5150   GOSUB 4230  'erase box
  507. 5160  REM  X First move
  508. 5170   GOSUB 1920    'ask for and make X move
  509. 5180  REM  O Second move Computer move
  510. 5190   IF SQ(5)=0 THEN MOVE=5:GOTO 5250 ELSE GOTO 5200
  511. 5200   I=INT((RND*3)+1)  'pick one of 4 corners randomly
  512. 5210   IF I=1 THEN MOVE=1
  513. 5220   IF I=2 THEN MOVE=3
  514. 5230   IF I=3 THEN MOVE=7
  515. 5240   IF I=4 THEN MOVE=9
  516. 5250   GOSUB 3360  'load coordinates for move
  517. 5260   GOSUB 3560  'draw move
  518. 5270  REM  X Third move
  519. 5280   GOSUB 1920    'ask for and make X move
  520. 5290  REM  O Fourth move, Computer move
  521. 5300   MOVE=0:GOSUB 4280   'check for 2 in row, win and stop opponent
  522. 5310   IF MOVE=0 THEN GOTO 5320 ELSE GOTO 5440  'if not 2 in row continue
  523. 5320     IF SQ(1)=4 AND SQ(9)=4 THEN GOTO 5350
  524. 5330     IF SQ(3)=4 AND SQ(7)=4 THEN GOTO 5350
  525. 5340    GOTO 5410 'pick a random move
  526. 5350     I=INT((RND*3)+1) 'pick one of 4 sides randomly
  527. 5360     IF I=1 THEN MOVE=2
  528. 5370     IF I=2 THEN MOVE=4
  529. 5380     IF I=3 THEN MOVE=6
  530. 5390     IF I=4 THEN MOVE=8
  531. 5400     GOTO 5440 'make move
  532. 5410    I=INT((RND*8)+1) 'pick random computer move
  533. 5420    IF SQ(I) <> 0 THEN GOTO 5350  'if square filled pick another
  534. 5430    MOVE=I
  535. 5440   GOSUB 3360:GOSUB 3560 'make move
  536. 5450  REM  X Fifth move
  537. 5460   GOSUB 1920 'ask for and make X move
  538. 5470   WINSW=0:GOSUB 2270  'check for win
  539. 5480   IF WINSW=4 THEN GOTO 5830   'X wins
  540. 5490  REM  O Sixth move, Computer move
  541. 5500    MOVE=0:GOSUB 4280   'check for 2 in row, win and stop opponent
  542. 5510    IF MOVE=0 THEN GOTO 5520 ELSE GOTO 5550  'if not 2 in row do random
  543. 5520   I=INT((RND*8)+1)  'pick random computer move
  544. 5530   IF SQ(I) <> 0 THEN GOTO 5520  'if square filled pick another
  545. 5540   MOVE=I
  546. 5550   GOSUB 3360:GOSUB 3560  'make move
  547. 5560   WINSW=0:GOSUB 2270  'check for win
  548. 5570   IF WINSW=1 THEN GOTO 5790   'Computer wins
  549. 5580  REM  X Seventh move
  550. 5590   GOSUB 1920    'ask for and make X move
  551. 5600   WINSW=0:GOSUB 2270  'check for win
  552. 5610   IF WINSW=4 THEN GOTO 5830   'X wins
  553. 5620  REM  O Eighth move, Computer move
  554. 5630    MOVE=0:GOSUB 4280 'check for 2 in row, win and stop opponent
  555. 5640    IF MOVE=0 THEN GOTO 5650 ELSE GOTO 5680  'if not 2 in row do random
  556. 5650   I=INT((RND*8)+1) 'pick random computer move
  557. 5660   IF SQ(I) <> 0 THEN GOTO 5650  'if square filled pick another
  558. 5670   MOVE=I
  559. 5680   GOSUB 3360:GOSUB 3560  'make move
  560. 5690   WINSW=0:GOSUB 2270  'check for win
  561. 5700   IF WINSW=1 THEN GOTO 5790   'Computer wins
  562. 5710  REM  X Nineth move
  563. 5720   GOSUB 1920    'ask for and make X move
  564. 5730   WINSW=0:GOSUB 2270  'check for win
  565. 5740   IF WINSW=4 THEN GOTO 5830   'X wins
  566. 5750  REM -- TIE --
  567. 5760   BEEP
  568. 5770   LOCATE 12,55,0:PRINT "  TIE    "
  569. 5780   GOTO 5860
  570. 5790  REM -- O WINS --
  571. 5800   BEEP
  572. 5810   LOCATE 12,55,0:PRINT " O - WINS"
  573. 5820   GOTO 5860
  574. 5830  REM -- X WINS --
  575. 5840   BEEP
  576. 5850   LOCATE 12,55,0:PRINT " X - WINS"
  577. 5860  COLOR 7,0  'Turn off blinking
  578. 5870  RETURN '---
  579. 5880  REM ---- Randomize Subroutine ---
  580. 5890   REM This subroutine substitutes for the randomize command. It picks off
  581. 5900   REM 4 digits from the time field and uses this to seed the random nbr.
  582. 5910   A$=TIME$
  583. 5920   B$=MID$(A$,4,2)+RIGHT$(A$,2)
  584. 5930   TIME=VAL(B$)
  585. 5940   RANDOMIZE TIME  'seed random nbr generator
  586. 5950  RETURN '---
  587.